package com.longxiao.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 字典
 * Created by houhongwei on 2017/4/28.
 */
public class Dictionary {

    private static Map<Object, Language> map = new HashMap<Object, Language>();

    public static enum LAN_KEY {
        NEED_LOGIN,
        SERVER_BUSY,

        GIFT_NOT_STAISFIED_CONDITION,
        GIFT_HAS_RECEIVED,

        LESS_THAN_24_HOUR,
        LESS_THAN_48_HOUR,

        UN_COMPLETE_APPOINTMENT,
        NOT_FOUND_CLASSROOM,

        COURSE_COMPLETE,
    }


    static {
        build(ResultCode.SUCCESS, "成功", "Success");

        build(LAN_KEY.NEED_LOGIN, "请先登录", "need login!");
        build(LAN_KEY.SERVER_BUSY, "系统繁忙请稍后再试", "System busy, please try again later!");
        build(LAN_KEY.GIFT_NOT_STAISFIED_CONDITION, "不满足领取条件", "System busy, please try again later!");
        build(LAN_KEY.GIFT_HAS_RECEIVED, "礼包已经领取过", "");

        build(LAN_KEY.LESS_THAN_24_HOUR, "距离开课时间不足24小时无法取消课程", "Less than 24 hours from the commencement of the course can not cancel the course");
        build(LAN_KEY.COURSE_COMPLETE, "太棒啦，您已经把所有的课程都学完啦！", "");
        build(LAN_KEY.LESS_THAN_48_HOUR, "必须预约48小时以后的课程", "");
        build(LAN_KEY.UN_COMPLETE_APPOINTMENT, "您有未上课的预约，请上完课之后再预约新的课程", "");
        build(LAN_KEY.NOT_FOUND_CLASSROOM, "不存在等待匹配的教室", "");
    }

    public static String getCn(Object key) {
        Language lan = map.get(key);
        if (lan != null) {
            return lan.getCn();
        }
        return null;
    }

    public static String getEn(Object key) {
        Language lan = map.get(key);
        if (lan != null) {
            return lan.getEn();
        }
        return null;
    }

    public static String get(Object key, String userId) {
        return (isStu(userId) == Boolean.TRUE ? getCn(key) : getEn(key));
    }

    private static String _1 = "1";// 学生
    private static String _2 = "2";// 老师

    // 判断用户ID是否为学生
    public static boolean isStu(String stuId) {
        String tmp = stuId.substring(0,1);
        return (tmp.equals(_1));
    }

    // 判断用户ID是否为老师
    public static boolean isTch(String tchId) {
        String tmp = tchId.substring(0,1);
        return (tmp.equals(_2));
    }

    // 限制访问权限，同一个包内可以访问
    static void build(Object key, String cn, String en) {
        map.put(key, new Language(cn, en));
    }

    private static Language build(String cn, String en) {
        return new Language(cn, en);
    }



    private static class Language {

        String cn;

        String en;

        public Language(String cn, String en) {
            this.cn = cn;
            this.en = en;
        }

        public String getCn() {
            return cn;
        }

        public String getEn() {
            return en;
        }
    }
}
